package com.zt.location.modules.base.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zt.location.common.utils.PageUtils;
import com.zt.location.common.utils.Query;
import com.zt.location.common.utils.R;
import com.zt.location.modules.base.entity.ReaderRelationEntity;
import com.zt.location.modules.base.service.ReaderRelationService;
import com.zt.location.modules.sys.entity.SysUserEntity;

/**
 * 
 * 
 * @author admin
 * @email obj_admin@163.com
 * @date 2019-05-02 14:28:20
 */
@RestController
@RequestMapping("/base/readerRelation")
public class ReaderRelationController {
	@Autowired
	private ReaderRelationService readerRelationService;

	/**
	 * 列表
	 */
	@RequestMapping("/qlist")
	@RequiresPermissions("base:readerRelation:qlist")
	public R qlist(@RequestParam Map<String, Object> params) {
		// 查询列表数据
		Query query = new Query(params);

		List<ReaderRelationEntity> groupList = readerRelationService.queryList(query);

		return R.ok().put("readerRelationList", groupList);
	}

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("base:readerRelation:list")
	public R list(@RequestParam Map<String, Object> params) {
		System.out.println("here --------------");
		// 查询列表数据
		Query query = new Query(params);

		List<ReaderRelationEntity> groupList = readerRelationService.queryList(query);
		int total = readerRelationService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(groupList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("base:readerRelation:info")
	public R info(@PathVariable("id") Integer id) {
		ReaderRelationEntity group = readerRelationService.queryObject(id);
		return R.ok().put("readerRelation", group);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("base:readerRelation:save")
	public R save(@RequestBody ReaderRelationEntity group) {
		String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
		group.setCuser(username);
		readerRelationService.save(group);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("base:readerRelation:update")
	public R update(@RequestBody ReaderRelationEntity group) {
		readerRelationService.update(group);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("base:readerRelation:delete")
	public R delete(@RequestBody Integer[] ids) {
		readerRelationService.deleteBatch(ids);
		return R.ok();
	}

}
